const fs = require('fs');
const path = require('path');

const useRouter = (app) => {
  const files = fs.readdirSync(__dirname);
  files.forEach((file) => {
    if (file !== 'index.js') {
      const router = require(path.resolve(__dirname, file));
      app.use(router.routes()).use(router.allowedMethods());
    }
  });
};

module.exports = useRouter;
